#include "stdio.h"

typedef struct Student
{
    char name[20];
    int age;
    int score;
}Stu;



int main() {
    Stu str[3] = {
        {"Tom", 18, 90},
        {"Jerry", 20, 75},
        {"Sam", 16, 85}
    };

    FILE *fp = fopen("student.txt", "w");
    if (fp == NULL) {
        printf("File open failed!\n");
        return 0;
    }
    for (int i = 0; i < 3; ++i) {
        fprintf(fp, "%s %d %d\n", str[i].name, str[i].age, str[i].score);
    }
    fclose(fp);

    fp = fopen("student.txt", "r");
    if (fp == NULL) {
        printf("File open failed!\n");
        return 0;
    }
    // while (fscanf(fp, "%s %d %d", str[0].name, &str[0].age, &str[0].score) != EOF) {
    //     printf("%s %d %d\n", str[0].name, str[0].age, str[0].score);
    // }

    for(int i=0; i < 3; i++){
        fscanf(fp, "%s %d %d", str[i].name, &str[i].age, &str[i].score);
    }
    fclose(fp);

    for (int i = 0; i < 3; ++i) {
        printf("%s %d %d\n", str[i].name, str[i].age, str[i].score);
    }

    return 0;

}